package com.lyp.crm.service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lyp.crm.dao.QiandaoMapper;
import com.lyp.crm.dao.UserMapper;
import com.lyp.crm.entity.Fenye;
import com.lyp.crm.entity.Qiandao;
import com.lyp.crm.entity.User;
import com.lyp.crm.entity.Userroles;

@Service
public class UserdaoImp implements Userdao{
	
	@Autowired
	private UserMapper usermapper;
	@Autowired
	private Fenye<User> fenye;
	@Autowired
	private QiandaoMapper qiandaomapper;
	
	SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd");
	SimpleDateFormat sdftime= new SimpleDateFormat("HH:mm:ss");
	Date date = new Date();
	@Override
	public User login(User user) {
		// TODO Auto-generated method stub
		return usermapper.login(user);
	}

	@Override
	public Integer updateupassnum(User user) {
		// TODO Auto-generated method stub
	
		usermapper.updateupassnum(user);
		return usermapper.updateupassnum(user);
	}

	@Override
	public Fenye<User> selectUser(Fenye<User> fenye) {
		List<User> rows = usermapper.selectUser(fenye);
		Integer total = usermapper.selectCountUser(fenye);
		fenye.setTotal(total);
		fenye.setRows(rows);
	
		return fenye;
	}

	@Override
	public Integer indeteUser(User user) {
		// TODO Auto-generated method stub
		return usermapper.indeteUser(user);
	}

	@Override
	public Integer deleteUser(Integer id) {
		//����uid���û���ɫ�м�����û���ɫ������
		Integer selectuserrolesuid = usermapper.selectuserrolesuid(id);
		//����в���ɾ��
		if (selectuserrolesuid>0) {
			return 0;
		} else {
			return	usermapper.deleteUser(id);
		}
		
			
	}

	@Override
	public Integer updateUser(User user) {
		//�޸�
		Integer updateUser = usermapper.updateUser(user);
		//ǩ��
		if (updateUser>0) {
			Qiandao qiandao=new Qiandao();
			qiandao.setQuid(user.getUid());
			qiandao.setQuname(user.getUname());
			qiandao.setQdate(sdf.format(date));
			qiandao.setQtime(sdftime.format(date));
			qiandao.setQstatus("�ٵ�");
			qiandao.setQqiantui("�����ϰ�");
			if (user.getUsign()==1) {
				qiandaomapper.insertQiandao(qiandao);
			}
			
		}
		
		
		return updateUser;
	}

	@Override
	public List<User> selectlist() {
		// TODO Auto-generated method stub
		return usermapper.selectlist();
	}
	
	
	
	

	@Override
	public Integer chongzhi(User user) {
		// TODO Auto-generated method stub
		return usermapper.chongzhi(user);
	}
	@Override
	public Integer xiugai(User user) {
		// TODO Auto-generated method stub
		return usermapper.xiugai(user);
	}
	
	@Override
	public Integer qiandao(User user) {
		// TODO Auto-generated method stub
		return usermapper.qiandao(user);
	}

	@Override
	public Integer quanbuqiantui() {
		// TODO Auto-generated method stub
		return usermapper.quanbuqiantui();
	}

	@Override
	public List<User> selectzixunshi() {
		// TODO Auto-generated method stub
		return usermapper.selectzixunshi();
	}

	@Override
	public User selectbyuid(Integer uid) {
		// TODO Auto-generated method stub
		return usermapper.selectbyuid(uid);
	}
}
